import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:flutter_base_app/config/theme.dart';
import 'package:flutter_base_app/widgets/dialog/popup/popup_select.dart';

import '../config/app_colors.dart';

class PopupInput extends StatelessWidget {
  final String title;
  final double width;
  final double height;
  final double? dialogHeight;
  final double dialogMaxHeight;
  final String select;

  //当选择后是否设置成hover样式
  final bool isSelectToHover;
  List<String> datas;
  final ValueChanged<String>? onChanged;
  final AsyncValueGetter<List<String>?>? onClicked;
  final tag = "popupInput";

  PopupInput({
    super.key,
    this.title = "选择",
    required this.select,
    List<String>? datas,
    this.width = 150,
    this.height = 40,
    this.dialogHeight,
    this.dialogMaxHeight = 240,
    this.isSelectToHover = false,
    this.onChanged,
    this.onClicked,
  }) : datas = datas ?? const [];
  final isHover = false.obs;

  bool get isSelect => select.isNotEmpty;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () async {
        final result = await onClicked?.call() ?? datas;
        datas = result;
        WidgetsBinding.instance.addPostFrameCallback((_) {
          showPopupList(
            context,
            datas: datas,
            selectedItem: select,
            width: width,
            height: height,
            dialogHeight: dialogHeight,
            dialogMaxHeight: dialogMaxHeight,
            // selectedItem: select,
            onChanged: onChanged,
          );
        });
      },
      onHover: (value) {
        isHover.value = value;
      },
      borderRadius: BorderRadius.circular(10),
      child: Obx(() => Container(
            width: width,
            height: height,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                border: Border.all(
                  color: (isSelectToHover && isSelect) || isHover.value ? primaryColor :ColorsApp.dividerColor,
                  width: 1,
                )),
            child: Center(
              child: Text(
                select.isEmpty ? title : select,
                style: TextStyle(color: (isSelectToHover && isSelect) || isHover.value ? primaryColor : ColorsApp.black, fontSize: 16),
              ),
            ),
          )),
      // child: InputDecorator(
      //   decoration: InputDecoration(
      //       labelText: title,
      //       contentPadding: EdgeInsets.zero,
      //       border: OutlineInputBorder(
      //         borderRadius: BorderRadius.circular(10.0),
      //       )),
      //   child: Center(
      //     child: Text(select),
      //   ),
      // ),
    );
  }
}
